package com.dave.gd.core.services.bean;

import java.io.Serializable;
import java.util.Collection;

/**
 * Created by linzq on 2014/11/3.
 */
public class ReqResult implements Serializable {
    private static final long serialVersionUID = 3069345797399506457L;
    
    /**
     * .
     */
    public final static String RET_SUCCESS = "0";
    
    /**
     * .
     */
    public final static String RET_ERROR = "1";
    
    /**
     * .
     */
    private String result;
    
    private String message;
    
    private Object[] data;
    
    public String getResult() {
        return result;
    }
    
    public void setResult(String result) {
        this.result = result;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public Object[] getData() {
        return data;
    }
    
    public void setData(Object[] data) {
        this.data = data;
    }
    
    public static ReqResult genReqResult(String resultCode, String msg, Object obj) {
        ReqResult result = new ReqResult();
        result.setResult(resultCode);
        result.setMessage(msg);
        if (obj != null) {
            if (obj instanceof Collection) {
                result.setData(((Collection<?>) obj).toArray());
            } else {
                result.setData(new Object[] {obj });
            }
        }
        return result;
    }
    
    public String getResultStr() {
        if (RET_SUCCESS.equals(this.getResult())) {
            return "成功";
        } else {
            return "失败";
        }
    }
    
    private HeadInfo headInfo = new HeadInfo();
    
    public HeadInfo getHeadInfo() {
        return headInfo;
    }
    
    public void setHeadInfo(HeadInfo headInfo) {
        this.headInfo = headInfo;
    }
    
}
